package com.situ.crm.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.situ.crm.entity.Menu;
import com.situ.crm.service.IMenuService;
import com.situ.crm.vo.MenuVO;
import com.situ.crm.vo.NavbarVO;
import com.situ.crm.vo.ResultDataVO;

//菜单控制器
@Controller
@RequestMapping(value = "/menus")
public class MenuController {

	@Autowired
	private IMenuService menuService;

	// 查询菜单
	@GetMapping(value = "/list")
	@ResponseBody
	public List<NavbarVO> selectMenuList() {
		return menuService.selectMenuList();
	}

	@GetMapping(value = "/index")
	public String openMenuPage() {
		return "menu";
	}

	@GetMapping(value = "/page")
	@ResponseBody
	public ResultDataVO selectMenus(String name, Integer page, Integer limit) {
		return menuService.selectMenuPage(name, page, limit);
	}

	@GetMapping(value = "/tops")
	@ResponseBody
	public List<Menu> selectTops() {
		return menuService.selectTops();
	}

	@PostMapping(value = "/save")
	@ResponseBody
	public void doSave(Menu menu) {
		menuService.doSave(menu);
	}

	@PostMapping(value = "/del")
	@ResponseBody
	public void delMenu(Integer id) {
		menuService.doDel(id);
	}

	@GetMapping(value = "/{id}")
	@ResponseBody
	public Menu selectById(@PathVariable("id") Integer id) {
		return menuService.selectById(id);
	}
	
	@GetMapping(value = "/tree")
	@ResponseBody
	public List<MenuVO> selectMenuTree(Integer roleId){
		return menuService.selectMenuTree(roleId);
	}
}
